"""
@Time ： 2023/7/15 0009 10:07
@Auth ： zpt
@File ：ALlProject.py
@IDE ：PyCharm
"""
import time

from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from Page.LoginPage import LoginPage
from selenium.webdriver.common.keys import Keys
from Lib.common_lib import LOG_INFO, LOG_ERROR


class AllProjects(object):
    """镜像定制页面"""
    cfg_name = "everything"
    cfg_repo = "https://repo.openeuler.org/openEuler-22.03-LTS/everything/"
    name = "python-flask"
    address = "https://gitee.com/src-openeuler/python-flask.git"

    def __init__(self, driver):
        self.driver = driver

    def get_url(self, url):
        self.driver.get(url)

    def user_login(self, user_name, password):
        """
        用户登录
        """
        login = LoginPage(self.driver)
        login.user_login()
        login.login_valid(user_name, password)

    def alert_message(self):
        """
        获取弹窗元素
        """
        mouse_alert = self.driver.find_element(By.XPATH, '/html/body/div[3]')
        ActionChains(self.driver).move_to_element(mouse_alert).perform()
        alert = self.driver.find_element(By.XPATH, '/html/body/div[3]')

        return alert.text

    def build_project_view(self):
        """
        构建工程查看按钮
        """
        try:
            self.driver.find_element(By.XPATH,
                                     '//*[@id="app"]/div[1]/div/div[2]/div/section/main/div[1]/div[1]/button/span').click()

        except Exception as e:
            message = '构建工程查看按钮定位失败'
            LOG_ERROR("error: found build_project timeout")
            print(e)
            LOG_INFO(message)

    def check_info(self):
        """
        project总体页面信息检查
        """
        try:
            # 标题检查
            name_title = self.driver.find_element(By.XPATH, '//div/h2[text()="全部工程"]')
            # 查找project输入框检查
            Search_Project = self.driver.find_element(By.XPATH, '//input[@placeholder="请输入工程名称"]')
            if Search_Project.is_displayed():
                Search_Project_info = '查找工程输入框显示正常'
            else:
                Search_Project_info = '查找工程输入框未正常显示'
            # 工程总数显示检查
            Total_Projects = self.driver.find_element(By.XPATH,
                                                      '/html/body/div[1]/div[1]/div/div[2]/div[1]/div/div['
                                                      '4]/div/span[1]')
            print(Total_Projects.text)
            if Total_Projects.is_displayed():
                Total_Projects_info = '工程总数显示正常'
            else:
                Total_Projects_info = '工程总数未正常显示'
            # 前往某页
            Goto_Page = self.driver.find_element(By.XPATH,
                                                 '//*[@id="app"]/div[1]/div/div[2]/div[1]/div/div[4]/div/span['
                                                 '3]/span[1]')
            print(Goto_Page.text)
            if Goto_Page.is_displayed():
                Goto_Page_info = '前往页面显示正常'
            else:
                Goto_Page_info = '前往页面未正常显示'

            return [name_title.text, Search_Project_info, Total_Projects_info, Goto_Page_info]
        except Exception as e:
            message = '流水线列表信息元素定位失败'
            LOG_ERROR("error: found page_info timeout")
            print(e)
            LOG_INFO(message)

    def project_List(self):
        """
        工程列表信息检查
        """
        Name = self.driver.find_element(By.XPATH, '//thead/tr/th/div[text()="名称"]')
        Description = self.driver.find_element(By.XPATH, '//thead/tr/th[2]/div[text()="描述"]')
        CreateTime = self.driver.find_element(By.XPATH, '//thead/tr/th[3]/div[text()="创建时间"]')

        return [Name.text, Description.text, CreateTime.text]

    def private_projects(self):
        """
        私有工程按钮
        """
        try:
            self.driver.find_element(By.XPATH,
                                     '//*[@id="app"]/div[1]/div/div[2]/div[1]/div/div[1]/div[2]').click()

        except Exception as e:
            message = '私有工程按钮定位失败'
            LOG_ERROR("error: found private_projects timeout")
            print(e)
            LOG_INFO(message)

    def public_projects(self):
        """
        公有工程按钮
        """
        try:
            self.driver.find_element(By.XPATH,
                                     '//*[@id="app"]/div[1]/div/div[2]/div[1]/div/div[1]/div[1]').click()
        except Exception as e:
            message = '公有工程按钮定位失败'
            LOG_ERROR("error: found public_projects timeout")
            print(e)
            LOG_INFO(message)

    def add_project_view(self):
        """
        添加工程弹窗界面
        """
        Title = self.driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/div[2]/div[2]/div/div/header/span')
        ProjectName = self.driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/div[2]/div['
                                                         '2]/div/div/div/form/div[1]/label')
        Description = self.driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/div[2]/div['
                                                         '2]/div/div/div/form/div[2]/label')
        Branch = self.driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/div[2]/div[2]/div/div/div/form/div['
                                                    '3]/label')

        input_Title = self.driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/div[2]/div['
                                                         '2]/div/div/div/form/div[1]/div/div[1]/div/input')
        if input_Title.is_displayed():
            input_Title_info = '标题输入框显示正常'
        else:
            input_Title_info = '查找工程输入框未正常显示'

        input_Description = self.driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/div[2]/div['
                                                               '2]/div/div/div/form/div[2]/div/div/div/input')
        if input_Description.is_displayed():
            input_Description_info = '描述输入框显示正常'
        else:
            input_Description_info = '描述输入框未正常显示'

        input_Branch = self.driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/div[2]/div['
                                                          '2]/div/div/div/form/div[3]/div/div/div/input')
        if input_Branch.is_displayed():
            input_Branch_info = '描述输入框显示正常'
        else:
            input_Branch_info = '描述输入框未正常显示'

        return [Title.text, ProjectName.text, Description.text, Branch.text, input_Title_info, input_Description_info,
                input_Branch_info]

    def add_project_view_cancel(self):
        """
        添加工程取消按钮
        """
        try:
            self.driver.find_element(By.XPATH,
                                     '//*[@id="app"]/div[1]/div/div[2]/div[2]/div/div/footer/div/button[2]').click()

        except Exception as e:
            message = '添加工程取消按钮定位失败'
            LOG_ERROR("error: found add project cancel timeout")
            print(e)
            LOG_INFO(message)

    def add_project_view_close(self):
        """
        添加工程关闭按钮
        """
        try:
            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div[2]/div/div/header/button').click()
            time.sleep(2)

            View_Title = self.driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/div[2]/div['
                                                            '2]/div/div/header/span')

            if View_Title.is_displayed():
                View_Title_info = '添加工程弹窗标题显示正常'
            else:
                View_Title_info = '添加工程弹窗标题未正常显示'

            return View_Title_info
        except Exception as e:
            message = '添加工程关闭按钮定位失败'
            LOG_ERROR("error: found add project close timeout")
            print(e)
            LOG_INFO(message)

    def Paging_dropdown_box(self):
        """
        分页下拉框检查
        """
        try:
            dropdown_box = self.driver.find_element(By.XPATH,
                                                    '/html/body/div[1]/div[1]/div/div[2]/div[1]/div/div[4]/div/span['
                                                    '2]/div/div/div/div/input').click()
            time.sleep(1)
            page_one = self.driver.find_element(By.XPATH, '/html/body/div[2]/div[3]/div/div/div[1]/ul/li[1]').click()
            dropdown_box.click()
            page_two = self.driver.find_element(By.XPATH, '/html/body/div[2]/div[3]/div/div/div[1]/ul/li[2]').click()
            dropdown_box.click()
            page_three = self.driver.find_element(By.XPATH, '/html/body/div[2]/div[3]/div/div/div[1]/ul/li[3]').click()
            dropdown_box.click()
            page_four = self.driver.find_element(By.XPATH, '/html/body/div[2]/div[3]/div/div/div[1]/ul/li[4]').click()
        except Exception as e:
            message = '添加工程按钮定位失败'
            LOG_ERROR("error: found Paging dropdown box timeout")
            print(e)
            LOG_INFO(message)
        # return [page_one.text, page_two.text, page_three.text, page_four.text]

    def add_project_btn(self):
        """
        添加工程按钮
        """
        try:
            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div[1]/div/div[2]/button/span').click()

        except Exception as e:
            message = '添加工程按钮定位失败'
            LOG_ERROR("error: found add project button timeout")
            print(e)
            LOG_INFO(message)

    def add_project(self, name):
        """
        添加工程功能
        """
        try:
            self.add_project_btn()
            time.sleep(2)
            self.driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/div[2]/div[2]/div/div/div/form/div['
                                               '1]/div/div[1]/div/input').send_keys(name)
        except Exception as e:
            message = '添加工程project name 输入框定位失败'
            LOG_ERROR("error: found add project project_name inputbox timeout")
            print(e)
            LOG_INFO(message)

    def add_project_confirm_btn(self):
        """
        添加工程确认按钮
        """
        try:
            self.driver.find_element(By.XPATH,
                                     '//*[@id="app"]/div[1]/div/div[2]/div[2]/div/div/footer/div/button[1]').click()
        except Exception as e:
            message = '添加工程确认按钮定位失败'
            LOG_ERROR("error:found add project confirm btn timeout")
            print(e)
            LOG_INFO(message)

    def enter_first_project(self, project_name=''):
        """
        进入第一个project
        """
        # 进入第一个project
        try:
            self.driver.find_element(By.XPATH, '//input[@placeholder="请输入工程名称"]').send_keys(project_name)
            time.sleep(2)
            self.driver.find_element(By.XPATH, '//input[@placeholder="请输入工程名称"]').send_keys(Keys.ENTER)
            time.sleep(2)
            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div[1]/div/div[3]/div/div[1]/div['
                                               '3]/div/div[1]/div/table/tbody/tr[1]/td[1]/div/span').click()

        except Exception as e:
            message = '进入第一个project定位失败'
            LOG_ERROR("error:found Enter the first project timeout")
            print(e)
            LOG_INFO(message)

    def get_first_project(self):
        """
        获取第一个工程名
        """
        name = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div[1]/div/div[3]/div/div[1]/div['
                                                  '3]/div/div[1]/div/table/tbody/tr[1]/td[1]/div/span').text

        return name

    def select_project_name(self, project_name):
        """
        project 选择框
        """
        try:
            select_project = self.driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/div[2]/div[1]/div/div['
                                                                '2]/div/div/div/input')
            select_project.send_keys(project_name)
            select_project.send_keys(Keys.ENTER)
        except Exception as e:
            message = 'project选择框定位失败'
            LOG_ERROR("error:found Project selection box timeout")
            print(e)
            LOG_INFO(message)

    def project_empty_text(self):
        """
        暂无数据
        """
        try:
            empty_text = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div[1]/div/div['
                                                            '3]/div/div[1]/div[3]/div/div[1]/div/div/span').text
            return empty_text
        except Exception as e:
            message = '暂无数据提示定位失败'
            LOG_ERROR("error: found no data available timeout")
            print(e)
            LOG_INFO(message)

    def project_veiw_name(self):
        """
        project view 的名称
        """
        try:
            project_title = self.driver.find_element(By.XPATH,
                                                     '//*[@id="app"]/div[1]/div/div[2]/div/div[1]/div[1]').text

            return project_title
        except Exception as e:
            message = 'project view 页面project 名称定位失败'
            LOG_ERROR("error: found Project view page project name timeout")
            print(e)
            LOG_INFO(message)

    def add_package_btn(self):
        """
        添加软件包按钮
        """
        try:
            self.driver.find_element(By.XPATH,
                                     '//*[@id="app"]/div[1]/div/div[2]/div/div['
                                     '3]/section/section/aside/div[1]/button/span').click()

        except Exception as e:
            message = '添加软件包按钮定位失败'
            LOG_ERROR("error: found add package button timeout")
            print(e)
            LOG_INFO(message)

    def Configure_package(self, name, address):
        """
        配置软件包信息
        """
        try:
            input_name = self.driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/div[2]/div/div[3]/div['
                                                            '1]/div/div/div/form/div[1]/div/div[1]/div/input')
            git_address = self.driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/div[2]/div/div[3]/div['
                                                             '1]/div/div/div/form/div[3]/div/div[1]/div/input')
            time.sleep(2)
            input_name.send_keys(name)
            time.sleep(2)
            git_address.send_keys(address)
        except Exception as e:
            message = '添加软件包输入框定位失败'
            LOG_ERROR("error: found add package inputbox timeout")
            print(e)
            LOG_INFO(message)

    def configure_package_confirm(self):
        """
        配置软件包确认按钮
        """
        try:
            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[3]/div['
                                               '1]/div/div/footer/div/button[1]/span').click()

        except Exception as e:
            message = '添加软件包确认按钮定位失败'
            LOG_ERROR("error: found add package confirm button timeout")
            print(e)
            LOG_INFO(message)

    def add_package_cancel_btn(self):
        """
        配置软件包取消按钮
        """
        try:
            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[3]/div['
                                               '1]/div/div/footer/div/button[2]/span').click()

        except Exception as e:
            message = '添加软件包取消按钮定位失败'
            LOG_ERROR("error: found add package cancel button timeout")
            print(e)
            LOG_INFO(message)

    def add_package_close_btn(self):
        """
        配置软件包关闭按钮
        """
        try:
            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[3]/div['
                                               '1]/div/div/header/button').click()

        except Exception as e:
            message = '添加软件包关闭按钮定位失败'
            LOG_ERROR("error: found add package close button timeout")
            print(e)
            LOG_INFO(message)

    def check_add_package_view_display(self):
        """
        添加软件包弹窗界面
        """
        add_package_title = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[3]/div['
                                                               '1]/div/div/header/span')
        if add_package_title.is_displayed():
            View_Title_info = '添加软件包弹窗标题显示正常'
        else:
            View_Title_info = '添加软件包弹窗标题未正常显示'
        return View_Title_info

    def project_add_package_cancel(self):
        """
        配置软件包取消按钮
        """
        self.private_projects()
        time.sleep(6)
        project_name = str(time.time())
        self.add_project(project_name)
        time.sleep(2)
        self.add_project_confirm_btn()
        time.sleep(2)
        self.enter_first_project()
        time.sleep(7)
        self.add_package_btn()
        time.sleep(10)
        self.add_package_cancel_btn()
        time.sleep(2)
        check_info = self.check_add_package_view_display()
        return check_info

    def project_add_package_close(self):
        """
        配置软件包确认按钮
        """
        self.private_projects()
        time.sleep(6)
        project_name = str(time.time())
        self.add_project(project_name)
        time.sleep(2)
        self.add_project_confirm_btn()
        time.sleep(2)
        self.enter_first_project()
        time.sleep(7)
        self.add_package_btn()
        time.sleep(10)
        self.add_package_close_btn()
        time.sleep(3)
        check_info = self.check_add_package_view_display()
        return check_info

    def add_private_project(self):
        """
        添加工程并进入创建的工程
        """
        self.private_projects()
        time.sleep(6)
        project_name = str(time.time())
        self.add_project(project_name)
        time.sleep(3)
        self.add_project_confirm_btn()
        time.sleep(6)
        self.enter_first_project(project_name)
        return project_name

    def project_add_Package(self, package_name='', git_url=''):
        """
        添加工程并配置软件包
        """
        self.private_projects()
        time.sleep(6)
        # project_name = str(time.time())
        # self.add_project(project_name)
        # time.sleep(3)
        # self.add_project_confirm_btn()
        # time.sleep(6)
        self.enter_first_project()
        time.sleep(10)
        # self.add_package_btn()
        # time.sleep(10)
        # self.Configure_package(package_name, git_url)
        # time.sleep(3)
        # self.configure_package_confirm()

    def full_build_btn(self):
        """
        全量构建按钮
        """
        try:
            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[3]/section/header/div['
                                               '2]/button[2]/span').click()
            self.driver.implicitly_wait(30)
            info = self.alert_message()
            return info
        except Exception as e:
            message = '全量构建按钮定位失败'
            LOG_ERROR("error: found full build button timeout")
            print(e)
            LOG_INFO(message)

    def incremental_build_btn(self):
        """
        增量构建按钮
        """
        try:
            self.driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/div[2]/div/div[3]/section/header/div['
                                               '2]/button[3]/span').click()
            self.driver.implicitly_wait(30)
            info = self.alert_message()
            return info

        except Exception as e:
            message = '增量构建按钮定位失败'
            LOG_ERROR("error: found incremental build button timeout")
            print(e)
            LOG_INFO(message)

    def single_build(self):
        """
        单包构建
        """
        try:
            self.driver.find_element(By.XPATH,
                                     '//*[@id="app"]/div[1]/div/div[2]/div/div[3]/div[1]/div[1]/div/button[1]').click()
            self.driver.implicitly_wait(30)
            info = self.alert_message()
            return info
        except Exception as e:
            message = '单包构建按钮定位失败'
            LOG_ERROR("error: found single build button timeout")
            print(e)
            LOG_INFO(message)

    def enter_first_package(self):
        """
        进入第一个软件包
        """
        try:
            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div['
                                               '3]/section/section/aside/div[2]/div/div[1]/div[3]/div/div['
                                               '1]/div/table/tbody/tr/td[1]/div/span').click()

        except Exception as e:
            message = '进入第一个软件包按钮定位失败'
            LOG_ERROR("error: Enter the first  package timeout")
            print(e)
            LOG_INFO(message)

    def get_first_package_name(self):
        """
        获取第一个软件包名称
        """
        try:
            package_name = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div['
                                                              '3]/section/section/aside/div[2]/div/div[1]/div[3]/div/div['
                                                              '1]/div/table/tbody/tr/td[1]/div/span')
            return package_name.text

        except Exception as e:
            message = '定位第一个软件包失败'
            LOG_ERROR("error: Found the first  package timeout")
            print(e)
            LOG_INFO(message)

    def add_build_target(self):
        """
       添加build_target
       """
        try:
            time.sleep(3)
            # 点击config 页签
            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div[3]').click()
            time.sleep(3)
            # 点击添加构建目标
            self.driver.find_element(By.XPATH,
                                     '//*[@id="app"]/div[1]/div/div[2]/div/div[3]/div[1]/div[1]/div[1]/div/div[1]/div['
                                     '1]/button/span').click()
            time.sleep(5)
            # 点击OS Variant下拉框
            self.driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/div[2]/div/div[3]/div[1]/div[1]/div['
                                               '1]/div/div[2]/div/div/div/form/div[1]/div/div/div/div/div/input').click()
            time.sleep(5)
            self.driver.find_element(By.XPATH, '/html/body/div[2]/div[3]/div/div/div[1]/ul/li[5]/span').click()
            time.sleep(5)
            # 点击 arch下拉框
            self.driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/div[2]/div/div[3]/div[1]/div[1]/div['
                                               '1]/div/div[2]/div/div/div/form/div[3]/div/div/div/div/div/input').click()
            time.sleep(5)
            self.driver.find_element(By.XPATH, '/html/body/div[2]/div[5]/div/div/div[1]/ul/li[1]/span').click()
            time.sleep(5)

            # 点击确认按钮
            self.driver.find_element(By.XPATH,
                                     '//*[@id="app"]/div[1]/div/div[2]/div/div[3]/div[1]/div[1]/div[1]/div/div['
                                     '2]/div/div/footer/span/button[1]/span').click()
        except Exception as e:
            message = '添加构建目标定位失败'
            LOG_ERROR("error: found build target timeout")
            print(e)
            LOG_INFO(message)

    def add_rpm_repo(self, name=cfg_name, repo=cfg_repo):
        """
       添加rpm repo
       """
        try:
            # 点击config 页签
            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div[3]').click()
            time.sleep(5)
            # 点击添加rpm repo 按钮
            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[3]/div[1]/div[1]/div[2]/div['
                                               '1]/button/span').click()
            time.sleep(1)
            self.driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/div[2]/div/div[3]/div['
                                               '2]/div/div/div/form/div[1]/div/div[1]/div/input').send_keys(name)
            time.sleep(1)
            self.driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/div[2]/div/div[3]/div['
                                               '2]/div/div/div/form/div[2]/div/div[1]/div/input').send_keys(repo)
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//*[@id="app"]/div[1]/div/div[2]/div/div[3]/div[2]/div/div/footer/span/button[1]').click()
        except Exception as e:
            message = '添加repo源定位失败'
            LOG_ERROR("error: add rpm repo timeout")
            print(e)
            LOG_INFO(message)

    def enter_overview_page(self):
        """
       进入project overview 页面
       """
        try:
            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div[1]').click()
        except Exception as e:
            message = '定位overview按钮失败'
            LOG_ERROR("error: found project overciew button timeout")
            print(e)
            LOG_INFO(message)

    def edit_description_btn(self):
        """
         修改描述按钮
        """
        self.private_projects()
        time.sleep(8)
        project_name = str(time.time())
        self.add_project(project_name)
        time.sleep(2)
        self.add_project_confirm_btn()
        time.sleep(2)
        self.enter_first_project()
        time.sleep(7)
        try:
            # description_btn = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[1]/div['
            #                                                      '2]/img')
            # WebDriverWait(self.driver, 20).until(lambda x: description_btn.is_displayed())
            # description_btn.click()
            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[1]/div[2]/img').click()
        except Exception as e:
            message = '定位edit description 按钮失败'
            LOG_ERROR("error: found edit description button timeout")
            print(e)
            LOG_INFO(message)

    def edit_description_input(self):
        """
       修改描述输入框
       """
        try:
            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[1]/div[2]/div['
                                               '@class="el-input el-input--suffix"]').send_keys("openEuler")
        except Exception as e:
            message = '定位定位描述输入框失败'
            LOG_ERROR("error: found  description inputbox timeout")
            print(e)
            LOG_INFO(message)

    def description_box_text(self):
        """
       描述文本
       """
        try:
            text = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[1]/div[2]/span').text
            return text
        except Exception as e:
            message = '定位描述内容失败'
            LOG_ERROR("error: found  description text  timeout")
            print(e)
            LOG_INFO(message)

    def project_overview_info(self):
        """
        页面信息检查
        """
        overview = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div[1]')
        build = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div[2]')
        config = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div[3]')
        user = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div[4]')
        Inherit_project = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div['
                                                             '3]/section/header/div[2]/button[1]/span')
        full_build = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div['
                                                        '3]/section/header/div[2]/button[2]/span')
        Incremental_build = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div['
                                                               '3]/section/header/div[2]/button[3]/span')
        unlock = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[3]/section/header/div['
                                                    '2]/button[4]/span/span')
        delete = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[3]/section/header/div['
                                                    '2]/button[5]/span')
        Packages = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div['
                                                      '3]/section/section/aside/h2')
        Build_results = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div['
                                                           '3]/section/section/main/h2')
        Package_name = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div['
                                                          '3]/section/section/aside/div[2]/div/div[1]/div['
                                                          '2]/table/thead/tr/th[1]/div')
        changed = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div['
                                                     '3]/section/section/aside/div[2]/div/div[1]/div['
                                                     '2]/table/thead/tr/th[2]/div')
        Os_variant = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div['
                                                        '3]/section/section/main/div/div/div[1]/div['
                                                        '2]/table/thead/tr/th[1]/div')
        arch = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div['
                                                  '3]/section/section/main/div/div/div[1]/div[2]/table/thead/tr/th['
                                                  '2]/div')
        status = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div['
                                                    '3]/section/section/main/div/div/div[1]/div[2]/table/thead/tr/th['
                                                    '3]/div')
        total = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div['
                                                   '3]/section/section/main/div/div/div[1]/div[2]/table/thead/tr/th['
                                                   '4]/div')
        refresh = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div['
                                                     '3]/section/section/main/button')
        element_list = [overview, build, config, user, Inherit_project, full_build, Incremental_build, unlock, delete,
                        Packages, Build_results, Package_name, changed, Os_variant, arch, status, total, refresh]

        return element_list

    def delete_project(self):
        """
       删除第一个工程
       """
        try:
            # 点击工程详情
            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[2]/div[1]').click()
            time.sleep(6)
            # 删除按钮
            delete_btn = self.driver.find_element(By.XPATH,
                                                  '//*[@id="app"]/div[1]/div/div[2]/div/div[3]/section/header/div['
                                                  '2]/button[5]')
            text = delete_btn.get_attribute('aria-disabled')
            if text == "ture":
                print("不是本次测试创建的工程")
            else:
                delete_btn.click()
                time.sleep(5)
                info = self.driver.find_element(By.XPATH, '//div/div[3]/div[3]/div[@aria-label="删除"]/div/div/div').text
                # 删除确认按钮
                self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[3]/div['
                                                   '3]/div/div/footer/div/span/button[1]/span').click()
                time.sleep(5)

                return info

        except Exception as e:
            message = '定位project 删除按钮失败'
            LOG_ERROR("error: found  project delete button timeout")
            print(e)
            LOG_INFO(message)

    def delete_my_project(self):
        project_title = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[1]/div[1]')
        if project_title.is_displayed():
            self.delete_project()
        else:
            exit(0)

    def add_package_name_alert(self):
        """
       软件包名必填校验信息
       """
        try:
            name_alert = self.driver.find_element(By.XPATH, '//div/div[2][text()="软件包名必填"]')
            return name_alert.text
        except Exception as e:
            message = '定位软件包名必填校验信息失败'
            LOG_ERROR("error: found package alert timeout")
            print(e)
            LOG_INFO(message)

    def add_package_url_alert(self):
        """
       软件包名git url校验信息
        """
        try:
            url_alert = self.driver.find_element(By.XPATH, '//div/div[2][text()="软件包git地址必填"]')
            return url_alert.text
        except Exception as e:
            message = '定位软件包git必填校验信息失败'
            LOG_ERROR("error: found package url alert timeout")
            print(e)
            LOG_INFO(message)

    def inherit_project_btn(self):
        """
        继承项目按钮
        """
        try:
            self.driver.find_element(By.XPATH,
                                     '//*[@id="app"]/div[1]/div/div[2]/div/div[3]/section/header/div[2]/button[1]').click()
        except Exception as e:
            message = '定位项目继承按钮失败'
            LOG_ERROR("error: found inherit project button  timeout")
            print(e)
            LOG_INFO(message)

    def inherit_project_view(self):
        """
        继承项目页面信息
        """
        title = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[3]/div['
                                                   '2]/div/div/header/span')
        if title.is_displayed():
            test_info1 = '继承项目界面标题正常显示'
        else:
            test_info1 = '继承项目界面标题未正常显示'
            # div[@aria-label="Inherit Project"]/div/div/form/div/div/div[1]/div/input
        name_input_box = self.driver.find_element(By.XPATH, '//div[@aria-label="继承工程"]/div/div/form/div/div/div['
                                                            '1]/div/input ')
        if name_input_box.is_displayed():
            test_info2 = '工程名称输入框正常显示'
        else:
            test_info2 = '工程名称输入框未正常显示'
        ok_btn = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[3]/div['
                                                    '2]/div/div/footer/div/button[1]')
        if ok_btn.is_displayed():
            test_info3 = 'ok按钮正常显示'
        else:
            test_info3 = 'ok按钮未正常显示'
        cancel_btn = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[3]/div['
                                                        '2]/div/div/footer/div/button[2]')
        if cancel_btn.is_displayed():
            test_info4 = '取消按钮正常显示'
        else:
            test_info4 = '取消按钮未正常显示'
        close_btn = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[3]/div['
                                                       '2]/div/div/header/button')
        if close_btn.is_displayed():
            test_info5 = '关闭按钮正常显示'
        else:
            test_info5 = '取消按钮未正常显示'

        return [test_info1, test_info2, test_info3, test_info4, test_info5]

    def inherit_project_close(self):
        """
         继承项目页面关闭按钮
        """
        try:

            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[3]/div['
                                               '2]/div/div/header/button').click()
        except Exception as e:
            message = '定位继承项目页面关闭按钮失败'
            LOG_ERROR("error: found inherit project close button  timeout")
            print(e)
            LOG_INFO(message)

    def inherit_project_ok(self):
        """
         继承项目页面确认按钮
        """
        try:

            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[3]/div['
                                               '2]/div/div/footer/div/button[1]').click()
        except Exception as e:
            message = '定位继承项目页面确认按钮失败'
            LOG_ERROR("error: found inherit project ok button  timeout")
            print(e)
            LOG_INFO(message)

    def inherit_project(self, new_name):
        """
        继承项目
        """
        self.driver.find_element(By.XPATH, '//div[@aria-label="继承工程"]/div/div/form/div/div/div['
                                           '1]/div/input').send_keys(new_name)
        time.sleep(3)
        # 确认按钮
        self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[3]/div['
                                           '2]/div/div/footer/div/button[1]').click()
        time.sleep(5)
        new_project_name = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[1]/div[1]').text

        return new_project_name

    def inherit_project_alert(self):
        """
          继承项目页面project name必填提示信息
         """
        try:
            inherit_name_alert = self.driver.find_element(By.XPATH, '//form/div/div/div[2][text()="工程名必填"]')
            return inherit_name_alert.text
        except Exception as e:
            message = '定位继承项目页面project name必填提示信息失败'
            LOG_ERROR("error: found inherit project name  alert timeout")
            print(e)
            LOG_INFO(message)

    def inherit_project_length_alert(self):
        """
          继承项目页面project name必填提示信息
         """
        try:
            inherit_length_alert = self.driver.find_element(By.XPATH, '//form/div/div/div[2][text('
                                                                      ')="project.projectLength"]')
            return inherit_length_alert.text
        except Exception as e:
            message = '定位继承项目页面project name必填提示信息失败'
            LOG_ERROR("error: found inherit project name  alert timeout")
            print(e)
            LOG_INFO(message)

    def lock_btn(self):
        """
        project overview 页面 lock按钮
        """
        try:
            lock_btn = self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div['
                                                          '3]/section/header/div[2]/button[4]')
            lock_btn.click()
            time.sleep(6)
            text1 = lock_btn.text
            lock_btn.click()
            time.sleep(3)
            text2 = lock_btn.text

            return [text1, text2]

        except Exception as e:
            message = '项目页面锁定按钮失败'
            LOG_ERROR("error: found  project overview lock button timeout")
            print(e)
            LOG_INFO(message)
